-
Notifications
You must be signed in to change notification settings - Fork 175
feat: Implement Random walk in py-libp2p #822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@sumanjeet0012 : Great progress on the Random Walk module! 🎉 The approach you’ve taken makes the module clean, extensible, and in line with the existing py-libp2p architecture. I especially appreciate: Alignment with specs – You’ve kept the implementation true to libp2p’s discovery goals, which will help ensure compatibility across implementations. Incremental progress – You’re clearly testing and refining as you go, which shows a disciplined approach to development. The random walk module is going to be a great step forward for py-libp2p’s peer discovery capabilities. Once it’s fully integrated, it will enhance the robustness and adaptability of the network layer — something that will benefit many projects using py-libp2p. Keep up the momentum! 🚀 Your work here is making py-libp2p stronger and more feature-complete, and it’s exciting to see it coming together. |
…n for peer discovery
@seetadev The Random walk module is now working as expected. This PR is now ready for review. |
Excellent progress, @Sumanjeet — great to hear that the Random Walk module is now working as expected. That’s a meaningful milestone since Random Walk is central to keeping peer discovery active and healthy in the network. By ensuring it works correctly, you’ve laid the groundwork for stronger connectivity and more resilient DHT lookups. It’s also really good to know you’re planning to add test cases and a screencast video. Both will add a lot of value: the tests will help us validate behavior across different scenarios, while the screencast will give everyone in the team a clear demonstration of the feature in action — always useful for reviews and onboarding new contributors. With the PR now ready for review, we can take a closer look at the implementation details and provide feedback. From your updates so far, the direction looks solid and thoughtful. Really appreciate the steady effort you’ve put into this — it’s helping move the project forward in a big way. Looking forward to reviewing the code and tests once they’re up. |
# Timing constants (matching go-libp2p) | ||
PEER_PING_TIMEOUT: Final[float] = 10.0 # seconds | ||
REFRESH_QUERY_TIMEOUT: Final[float] = 60.0 # seconds | ||
REFRESH_INTERVAL: Final[float] = 10.0 # 10 seconds for demonstration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everywhere else, this value is 300, but here it is 10.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was done for fast local testing, Now corrected it to 300 seconds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't appear that large portions of the code in this file (start
, _main_loop
, _do_refresh
) are hit during test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some more tests covering these functions.
|
||
|
||
@pytest.mark.trio | ||
async def test_perform_random_walk_running(mock_host, dummy_peer_id): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cover case where no peers found returns as expected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a test case for the scenario where no peers are found, which returns an empty array.
Hey @sumanjeet0012, looks good. Just a few comments. Thanks for getting this together! |
@pacrob Ready for next round of review. |
Found one extra paren in a log comment, remove that and I think it's good to merge. |
Co-authored-by: Paul Robinson <[email protected]>
What was wrong?
Fixes #788
Random Walk Module was not present in py-libp2p. The py-libp2p library lacked a Random Walk mechanism for its DHT implementation, which is essential for continuous peer discovery and maintaining a healthy routing table in dynamic peer-to-peer networks.
How was it fixed?
Implemented Random Walk module in py-libp2p with the following key components:
1. Core Module Implementation
libp2p/discovery/random_walk/
directory with:random_walk.py
: MainRandomWalkDiscovery
class that performs periodic random peer lookupsutils.py
: Random peer ID generation and lookup utilities__init__.py
: Module exports2. DHT Integration
3. Key Features
FIND_NODE
queries4. Background Process Management
5. Examples and Tests
To-Do
Cute Animal Picture